package cn.itsource.service.impl;

import cn.itsource.enums.CategoryType;
import cn.itsource.mapper.CategoryMapper;
import cn.itsource.pojo.Carousel;
import cn.itsource.pojo.Category;
import cn.itsource.pojo.vo.CategoryVo;
import cn.itsource.pojo.vo.NewItemVo;
import cn.itsource.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Category> queryAllRootLevelCat() {
        return categoryMapper.findAllByType(CategoryType.F.type);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<CategoryVo> querySubCatList(Integer rootCatId) {
        return categoryMapper.getSubCatList(rootCatId);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<NewItemVo> querySixNewItemsLazy(Integer rootCatId) {
        Map<String, Object> map = new HashMap<>();
        map.put("rootCatId", rootCatId);

        return categoryMapper.querySixNewItemsLazy(map);
    }
}
